package com.example.demo.util;

import java.util.Map;
import java.util.TreeMap;

/**
 * Created by song on 2018/1/22.
 */
public class AddressUtil {
    public static Map<String, String> provinceMap = new TreeMap<>();
    static {
        provinceMap.put("11", "北京");
        provinceMap.put("12", "天津");
        provinceMap.put("13", "河北省");
        provinceMap.put("14", "山西省");
        provinceMap.put("15", "内蒙古自治区");
        provinceMap.put("21", "辽宁省");
        provinceMap.put("22", "吉林省");
        provinceMap.put("23", "黑龙江省");
        provinceMap.put("31", "上海");
        provinceMap.put("32", "江苏省");
        provinceMap.put("33", "浙江省");
        provinceMap.put("34", "安徽省");
        provinceMap.put("35", "福建省");
        provinceMap.put("36", "江西省");
        provinceMap.put("37", "山东省");
        provinceMap.put("41", "河南省");
        provinceMap.put("42", "湖北省");
        provinceMap.put("43", "湖南省");
        provinceMap.put("44", "广东省");
        provinceMap.put("45", "广西壮族自治区");
        provinceMap.put("46", "海南省");
        provinceMap.put("50", "重庆");
        provinceMap.put("51", "四川省");
        provinceMap.put("52", "贵州省");
        provinceMap.put("53", "云南省");
        provinceMap.put("54", "西藏自治区");
        provinceMap.put("61", "陕西省");
        provinceMap.put("62", "甘肃省");
        provinceMap.put("63", "青海省");
        provinceMap.put("64", "宁夏回族自治区");
        provinceMap.put("65", "新疆维吾尔自治区");
        provinceMap.put("71", "台湾");
        provinceMap.put("81", "香港特别行政区");
        provinceMap.put("82", "澳门特别行政区");
        provinceMap.put("99", "海外");
    }

    public static String getProvinceByShortCode(String code){
        String province = provinceMap.get(code);
        if(province == null)
            return "其他";
        return province;
    }

    public static String getProvinceByFullCode(String code){
        if(code.length() > 15){
            code = code.substring(2,4);
        }else
            code = code.substring(0,2);
        return getProvinceByShortCode(code);
    }

}
